package dk.simonvogensen.itodo.client.model;

import com.google.gwt.user.client.rpc.IsSerializable;

import java.util.List;

/**
 * @author $LastChangedBy: vogensen@gmail.com $ $LastChangedDate: 2009-04-12 10:03:55 +0200 (Sun, 12 Apr 2009) $
 * @version $Revision: 18 $
 */
public class TransportType implements IsSerializable {

    private String name;
    private int transportTimeInMinutes;

    public TransportType() {
    }

    public TransportType(String name, int transportTimeInMinutes) {
        this.name = name;
        this.transportTimeInMinutes = transportTimeInMinutes;
    }

    public String getName() {
        return name;
    }

    public static TransportType parseString(String transportType, List<TransportType> transportTypeList) {
        for (TransportType tt : transportTypeList) {
            if (tt.getName().equals(transportType)) return tt;
        }
        return null;
    }

    public int getTransportTime() {
        return transportTimeInMinutes;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TransportType that = (TransportType) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + transportTimeInMinutes;
        return result;
    }

    @Override
    public String toString() {
        return "name=" + name;
    }
}
